package zjh_20230313;

import java.util.*;

public class Demo04 {
    static class Student {
        private int id = new Random().nextInt(40) + 1;
        private int score = new Random().nextInt(101);

        public Student() {
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public int getScore() {
            return score;
        }

        public void setScore(int score) {
            this.score = score;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "id=" + id +
                    ", score=" + score +
                    '}';
        }
    }

    public static void main(String[] args) {
        int sum = 0;
        LinkedList<Student> list = new LinkedList();
        while (sum < 20) {
            Student student = new Student();
            if (!list.contains(student.id)) {
                list.add(student);
                sum++;
            }
        }

        System.out.println(list.getFirst());
        System.out.println(list.getLast());
        System.out.println("==========");

        for (Student stu : list) {
            System.out.println(stu.toString());
        }
    }

}
